package com.asifrc.tw101;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by asifrc on 2/11/14.
 */
public class PrimeFactorsExercise {
    public static void main(String[] args) {
        PrimeFactorsExercise exercise = new PrimeFactorsExercise();
        System.out.println(exercise.generate(30));
    }

    private List<Integer> generate(int n) {
        List<Integer> factors = new LinkedList<Integer>();
        for (int i = 2; i < n; i++) {
            if ((30 % i) == 0) {
                if (isPrime(i, factors)) {
                    factors.add(i);
                }
            }
        }
        return factors;
    }

    private boolean isPrime(int x, List<Integer> factors) {
        for (Integer factor : factors) {
            if ((x % factor) == 0) {
                return false;
            }
        }
        return true;
    }
}
